/************************************************************************/
/*  									*/
/*  perturb_MI.c							*/
/*									*/
/*  Tom Lookabaugh							*/
/*  August 13, 1987							*/
/*  Last Revision: August 14, 1987					*/
/*									*/
/*  DESCRIPTION								*/
/*	Modified Itakura Version.  Perturbs a codeword by taking the	*/
/*	average normalized autocorrelations that were used to generate	*/
/*	the codeword, mixing them with a little white noise, and	*/
/*	then running Levinson's algorithm to generate the perturbed	*/
/*	codeword.							*/
/*  RETURNS								*/
/*	No significant value.  Modifies storage pointed to by target.	*/
/*  CALLS								*/
/*	autometh().							*/
/*									*/
/************************************************************************/

#include "stdvq.h"

perturb (source, target, add_off, mult_off) 

    double *source;	/* source vector (to be perturbed)		*/
    double *target;	/* target vector 				*/
    double add_off;	/* additive offset				*/
    double mult_off;	/* multiplicative offset			*/

{

    double double_temp;		/* temporary storage			*/
    double mag;			/* magnitude of perturbation		*/
    double* mixed_autocor;	/* autocor's mixed with white noise	*/
    int i;			/* iteration counter			*/


    if ((mixed_autocor = (double *)calloc(cdbkupdim, sizeof(double))) == NULL)
        error("insufficient memory availiable (perturb 1)");

    mag = mult_off*rand()/2147483647.0;
    mixed_autocor[0] = source[0];
    for (i = 1; i < cdbkupdim; i++) mixed_autocor[i] = 
      (1.0 - mag)*source[i];
    autometh(mixed_autocor, cdbkupdim - 1, target, &double_temp);

    free(mixed_autocor);
    
    
}
